package com.zhongjinkang.rhythm.Model

import android.util.Log
import com.huang.mylibrary.bean.ImageListInfo
import com.huang.mylibrary.bean.UserInfo
import com.huang.mylibrary.db.DBHelper
import com.zhongjinkang.rhythm.network.HttpUtil
import com.zhongjinkang.rhythm.network.RequestBuilder
import com.zhongjinkang.rhythm.network.api.HttpCallBack
import com.zhongjinkang.rhythm.network.api.RequestApi
import com.zhongjinkang.rhythm.network.res.BaseResponse
import com.zhongjinkang.rhythm.network.res.UserRes
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import kotlin.random.Random

class LoginModel : BaseModel() {
    val random: Random = Random;
    var id: Long = 0L;


    fun requestLogin(httpCallBack: HttpCallBack<UserRes>) {
        saveUserInfo()
        HttpUtil.getUserInfo(token, httpCallBack)

    }

    private fun saveUserInfo() {
        if (DBHelper.getInstance().userInfoHelper.userInfo.isEmpty())
            DBHelper.getInstance().userInfoHelper.addUserInfo(
                arrayListOf(
                    createUserInfo(
                        id,
                        "1https://8xhnx.xyz:8443/wp-content/uploads/Table_140.webp",
                        "国模001",
                        random.nextLong()
                    ),
                    createUserInfo(
                        addId(),
                        "1https://8xhnx.xyz:8443/p/2018/11/03003228/2018-11-02_16-32-27_638317.webp",
                        "国模002",
                        random.nextLong()
                    )

                )
            )
    }


    private fun createUserInfo(id: Long, url: String, name: String, peopleId: Long): UserInfo {
        val userInfo = UserInfo()
        userInfo.id = id;
        userInfo.url = url
        userInfo.name = name
        userInfo.peopleId = peopleId

        return userInfo;
    }


    fun saveUserInfoList() {
        if (DBHelper.getInstance().imageListInfoHelper.dataIsEmp() == 0) {
            val list = DBHelper.getInstance().userInfoHelper.userInfo;
            DBHelper.getInstance().imageListInfoHelper.addList(savePeopleList(list[0].peopleId))
            DBHelper.getInstance().imageListInfoHelper.addList(savePeopleList2(list[1].peopleId))
        }
    }


    private fun savePeopleList(peopleId: Long): List<ImageListInfo> {
        return arrayListOf(
            savePeople(
                addId(), peopleId,
                "1https://8xhnx.xyz:8443/p/2018/11/03003228/2018-11-02_16-32-27_638317.webp"
            ),
            savePeople(
                addId(), peopleId,
                "1https://8xhnx.xyz:8443/p/2018/11/03003234/2018-11-02_16-32-33_411998.webp"
            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003150/2018-11-02_16-31-49_124862.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003155/2018-11-02_16-31-54_556535.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003201/2018-11-02_16-32-00_817697.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003206/2018-11-02_16-32-05_220371.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003215/2018-11-02_16-32-14_062080.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003210/2018-11-02_16-32-09_622230.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003219/2018-11-02_16-32-18_305383.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003223/2018-11-02_16-32-22_741377.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003253/2018-11-02_16-32-52_745338.webp"
//            ),
//            savePeople(
//                addId(), peopleId,
//                "https://8xhnx.xyz:8443/p/2018/11/03003249/2018-11-02_16-32-48_533193.webp"
//            )
        )
    }

    private fun savePeopleList2(peopleId: Long): List<ImageListInfo> {
        return arrayListOf(
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_140.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_139.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_142.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_127.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_128.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_130.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_129.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_167.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_168.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_169.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_170.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_171.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_172.webp"
            ),
            savePeople(
                addId(),
                peopleId,
                "1https://8xhnx.xyz:8443/wp-content/uploads/Table_173.webp"
            ),

            )
    }

    private fun savePeople(id: Long, peopleId: Long, url: String): ImageListInfo {
        val imageListInfo = ImageListInfo();
        imageListInfo.peopleId = peopleId;
        imageListInfo.url = url
        imageListInfo.id = id;
        return imageListInfo
    }

    private fun addId(): Long {
        id += 1;
        return id;
    }
}